class UserCenter {
    constructor() {
        this.init();
        this.bindEvents();
    }

    init() {
        // 创建下拉菜单
        const dropdownHTML = `
            <div class="user-dropdown">
                <div class="dropdown-item" id="editProfile">修改信息</div>
                <div class="dropdown-divider"></div>
                <div class="dropdown-item" id="logout">退出登录</div>
            </div>
        `;
        
        const userCenter = document.querySelector('.user-center');
        userCenter.insertAdjacentHTML('beforeend', dropdownHTML);

        this.userCenter = userCenter;
        this.dropdown = userCenter.querySelector('.user-dropdown');
    }

    bindEvents() {
        // 切换下拉菜单显示状态
        this.userCenter.addEventListener('click', (e) => {
            e.stopPropagation();
            this.toggleDropdown();
        });

        // 点击其他地方关闭下拉菜单
        document.addEventListener('click', () => {
            this.dropdown.classList.remove('show');
        });

        // 处理菜单项点击
        document.getElementById('editProfile').addEventListener('click', (e) => {
            e.stopPropagation();
            this.handleEditProfile();
        });

        document.getElementById('logout').addEventListener('click', (e) => {
            e.stopPropagation();
            this.handleLogout();
        });
    }

    toggleDropdown() {
        this.dropdown.classList.toggle('show');
    }

    handleEditProfile() {
        // TODO: 实现修改信息功能
        alert('修改信息功能开发中...');
    }

    handleLogout() {
        // TODO: 实现退出登录功能
        const confirmed = confirm('确定要退出登录吗？');
        if (confirmed) {
            // 这里可以添加退出登录的逻辑
            alert('退出登录成功');
            // window.location.href = '/login'; // 跳转到登录页面
        }
    }
}